package com.example.zk2.fg

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.viewpager2.widget.ViewPager2
import com.example.base.mvvm.BaseViewFragment
import com.example.zk2.R
import com.example.zk2.adapter.MyTabEntity
import com.example.zk2.adapter.VpAdapter
import com.example.zk2.databinding.FragmentIndexBinding
import com.example.zk2.indexfg.CdFragment
import com.example.zk2.indexfg.GzFragment
import com.example.zk2.indexfg.TjFragment
import com.flyco.tablayout.listener.CustomTabEntity
import com.flyco.tablayout.listener.OnTabSelectListener

class IndexFragment : BaseViewFragment<FragmentIndexBinding>() {
    val list = mutableListOf<Fragment>()
    lateinit var vpAdapter: VpAdapter
    val tablist = arrayListOf<CustomTabEntity>()
    override fun initView() {
        list.add(GzFragment())
        list.add(TjFragment())
        list.add(CdFragment())
        vpAdapter = VpAdapter(requireActivity(),list)
        binding.vp.adapter = vpAdapter

        //commonTabLayout
        tablist.add(MyTabEntity("关注",0,0))
        tablist.add(MyTabEntity("推荐",0,0))
        tablist.add(MyTabEntity("成都",0,0))
        binding.common.setTabData(tablist)

        //联动
        binding.vp.registerOnPageChangeCallback(object :ViewPager2.OnPageChangeCallback(){
            override fun onPageSelected(position: Int) {
                super.onPageSelected(position)
                binding.common.currentTab = position
            }
        })
        binding.common.setOnTabSelectListener(object :OnTabSelectListener{
            override fun onTabSelect(position: Int) {
                binding.vp.currentItem = position
            }

            override fun onTabReselect(position: Int) {

            }
        })

    }

    override fun initData() {

    }

    override fun getLayout(): Int {
        return R.layout.fragment_index
    }

}